package com.suse.warmstill.config;

import com.suse.warmstill.autho.JwtIntercepter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/*
 *
 * 跨域请求
 * */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private JwtIntercepter intercepter;


    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                // .allowedOrigins("*")
                .allowedOriginPatterns("*")
                .allowedHeaders("*")
                .allowedMethods("*")
                .allowCredentials(true);


    }


    //不拦截
    String[] excludePath = {
            "/warmstill/user/getLoginImageCode",
            "/warmstill/user/user-tokens",
            //   "/warmstill/user/logoutUser/** ",
            "/doc.html",
            "/swagger-resources",
            "classpath:/META-INF/resources/",
            "classpath:/META-INF/resources/webjars/",
            "/webjars/**"
    };


    /**
     * 测试接口期间 先注解调
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(intercepter).excludePathPatterns(excludePath);
        WebMvcConfigurer.super.addInterceptors(registry);
    }

}
